package com.cy.deepseeksport.NLP;

import com.cy.deepseeksport.aiService.BochaApi;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionRequest;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import io.github.pigmesh.ai.deepseek.core.chat.UserMessage;
import io.milvus.grpc.JSONArray;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Slf4j
@CrossOrigin("*")
@RestController
public class HuoshanController {

    @Resource
    @Qualifier("huoshanDeepSeekClient")
    private DeepSeekClient huoshanDeepSeekClient;

    @Resource
    @Qualifier("oupaiDeepSeekClient")
    private DeepSeekClient oupaiDeepSeekClient;

    @Resource
    @Qualifier("deepSeekr1Client")
    private DeepSeekClient deepSeekr1Client;

    @Resource
    @Qualifier("qwenClient")
    private DeepSeekClient qwenClient;


    @GetMapping(value = "/doubao32kpro", produces = MediaType.TEXT_EVENT_STREAM_VALUE + ";charset=UTF-8")
    public Flux<ChatCompletionResponse> tangent(String prompt) throws IOException {


        //  欧派元

        ChatCompletionRequest request = ChatCompletionRequest.builder()
                .messages(Collections.singletonList(
                        UserMessage.from(prompt)
                ))
                .temperature(0.7)
                .maxTokens(2048)
                .build();

        return huoshanDeepSeekClient.chatFluxCompletion(request);

    }

    @GetMapping(value = "/llama3", produces = MediaType.TEXT_EVENT_STREAM_VALUE + ";charset=UTF-8")
    public Flux<ChatCompletionResponse> oupai(String prompt) throws IOException {


        //  欧派元

        ChatCompletionRequest request = ChatCompletionRequest.builder()
                .messages(Collections.singletonList(
                        UserMessage.from(prompt)
                ))
                .temperature(0.7)
                .maxTokens(2048)
                .build();

        return oupaiDeepSeekClient.chatFluxCompletion(request);

    }

    @GetMapping(value = "/deepseekr1", produces = MediaType.TEXT_EVENT_STREAM_VALUE + ";charset=UTF-8")
    public Flux<ChatCompletionResponse> deepseekr1(String prompt) throws IOException {


        //  欧派元

        ChatCompletionRequest request = ChatCompletionRequest.builder()
                .messages(Collections.singletonList(
                        UserMessage.from(prompt)
                ))
                .temperature(0.7)
                .maxTokens(2048)
                .build();

        return deepSeekr1Client.chatFluxCompletion(request);

    }


    @GetMapping(value = "/qwen3", produces = MediaType.TEXT_EVENT_STREAM_VALUE + ";charset=UTF-8")
    public Flux<ChatCompletionResponse> qwenClient(String prompt) throws IOException {


        //  欧派元

        ChatCompletionRequest request = ChatCompletionRequest.builder()
                .messages(Collections.singletonList(
                        UserMessage.from(prompt)
                ))
                .temperature(0.7)
                .maxTokens(2048)
                .build();

        return qwenClient.chatFluxCompletion(request);

    }


    @GetMapping("models")
    public List<HashMap> getModels() throws IOException {

        List<HashMap> models = new ArrayList<>();
        HashMap<String, String> model = new HashMap<>();
        model.put("name", "Deepseek R1");
        model.put("path", "deepseekr1");
        models.add(model);

        HashMap<String, String> model2 = new HashMap<>();
        model2.put("name", "Doubao 32k pro");
        model2.put("path", "doubao32kpro");
        models.add(model2);

        HashMap<String, String> model3 = new HashMap<>();
        model3.put("name", "Qwen3");
        model3.put("path", "qwen3");
        models.add(model3);

        HashMap<String, String> model4 = new HashMap<>();
        model4.put("name", "llama3");
        model4.put("path", "llama3");
        models.add(model4);

        return models;

    }



}
